package com.cloud.client.cloudclient.service.impl;

import com.cloud.client.cloudclient.service.ClientService;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class ClientServiceImpl implements ClientService {
	@Autowired
	private EurekaClient eurekaClient;

	@Autowired
	private RestTemplate restTemplate;

	@Override
	public String getClientServer() {
		InstanceInfo nextServerFromEureka = eurekaClient.getNextServerFromEureka("client2-service", false);
		String result=restTemplate.getForObject(nextServerFromEureka.getHomePageUrl()+"/",String.class);
		return result;
	}
}
